//div获取
var index = document.getElementById('index')
var js = document.getElementById('js')
var css = document.getElementById('css')
var vue = document.getElementById('vue')
var html = document.getElementById('html')
var jquery = document.getElementById('jquery')
var back = document.getElementById('back')
var wenzi = document.getElementsByClassName('wenzi')//遍历用

var item = document.getElementsByClassName('item')//目录

var guide = document.getElementById('guide')//导航

//a获取
var a = document.getElementsByTagName('a')

var js_a = js.getElementsByTagName('a')
var vue_a = vue.getElementsByTagName('a')
var html_a = html.getElementsByTagName('a')
var jquery_a = jquery.getElementsByTagName('a')
var css_a = css.getElementsByTagName('a')

if (window.location.search == '') location.href = 'log.html'//防盗链
var str = JSON.parse(decodeURI(window.location.search).substring(1))//解析地址栏
var username = str.username//获取用户名

//初始化
function init() {
    for (var i = 0; i < wenzi.length; i++) {
        guide.style.display = 'flex'
        wenzi[i].style.display = 'none'
    }
}
init()
wenzi[0].style.display = 'block'
guide.style.display = 'none'

//钩子清除
function remove() {
    for (var i = 1; i < a.length; i++) {
        a[i].removeAttribute('id')
    }
}

//上钩子
function add(a) {
    for (var i = 0; i < a.length; i++) {
        a[i].setAttribute('id', i)
    }
}

//首页
item[0].onclick = function () {
    init()
    guide.style.display = 'none'
    index.style.display = 'block'
}
//js
item[1].onclick = function () {
    init()
    js.style.display = 'block'
    remove()
    add(js_a)
}
//css
item[2].onclick = function () {
    init()
    css.style.display = 'block'
    remove()
    add(css_a)
}
//vue
item[3].onclick = function () {
    init()
    vue.style.display = 'block'
    remove()
    add(vue_a)
}
//html
item[4].onclick = function () {
    init()
    html.style.display = 'block'
    remove()
    add(html_a)
}
//jquery
item[5].onclick = function () {
    init()
    jquery.style.display = 'block'
    remove()
    add(jquery_a)
}
//返回
back.onclick = function () {
    location.href = './index.html?' + JSON.stringify({ code: str.code, username: username })
}

